<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class AutogeneratorViewXml_element extends JViewLegacy
{
	protected $form;

	protected $item;

	protected $state;

    public $iXmlTypeId;
    
	public function display($tpl = null)
	{
        $this->oApplication = JFactory::getApplication();
        $this->iXmlTypeId = $this->oApplication->input->getInt('iXmlTypeId');
        if ($this->iXmlTypeId < 1)
        {
            $sLink = JRoute::_('index.php?option=com_autogenerator&view=xml_types', false);
            
            $this->oApplication->redirect($sLink, JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_XML_TYPE_ID_IS_NOT_VALID'), 'error');
        }
        
		$this->form		= $this->get('Form');
		$this->item		= $this->get('Item');
		$this->state	= $this->get('State');
		
		$this->addToolbar();
		
		parent::display($tpl);
	}
	
	protected function addToolbar()
	{
        $oApplication = JFactory::getApplication();
        
		$oApplication->input->set('hidemainmenu', true);
        
        $sLayout = $oApplication->input->getString('layout');
        
        if ($sLayout == 'add')
        {
            JToolbarHelper::title(JText::_('COM_AUTOGENERATOR_XML_ELEMENT_ADD_DETAILS'), 'article.png');

            JToolbarHelper::apply('xml_element.apply');
            JToolbarHelper::save('xml_element.save');
        }
        elseif ($sLayout == 'delete')
        {
            JToolbarHelper::title(JText::_('COM_AUTOGENERATOR_XML_ELEMENT_DELETE_DETAILS'), 'article.png');

            JToolbarHelper::deleteList(JText::_('COM_AUTOGENERATOR_MESSAGE_CONFIRM_DELETE'), 'remove');
        }
        
		JToolbarHelper::cancel('xml_element.cancel');
	}
}
